package cn.lyjuan.citycode.pinyin.thread;

import bean.CityCodeBean;
import cn.lyjuan.base.util.PinyinUtils;
import cn.lyjuan.base.util.StringUtils;
import cn.lyjuan.citycode.pinyin.manager.PinyinManager;

public class PinyinRunnable implements Runnable
{
    private CityCodeBean bean;

    private PinyinManager waitObj;

    private String name;

    public PinyinRunnable(PinyinManager waitObj, CityCodeBean bean)
    {
        this.bean = bean;
        this.waitObj = waitObj;
    }

    public void run()
    {
        this.name = "pinyin-[" + bean.getId() + ":" + bean.getName() + "]";
        Thread.currentThread().setName(name);

        if (!StringUtils.isNull(bean.getPinyin())
                && !StringUtils.isNull(bean.getPinyin_simple()))
        {
            System.out.println(name + " pinyin exists");
            waitObj.notifyThrow();
            return;
        }

        String[] pinyins = PinyinUtils.pinyinAndSimple(bean.getName());

        bean.setPinyin(pinyins[0]);
        bean.setPinyin_simple(pinyins[1]);
        System.out.println(name + " covert compiled: " + pinyins[0] + ":" + pinyins[1]);
        waitObj.notifyThrow();
    }
}
